

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>dynamic_rest.fields &mdash; Dynamic REST 1.3.15 documentation</title>
  

  
  

  

  
  
    

  

  
  
    <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
  

  

  
    <link rel="top" title="Dynamic REST 1.3.15 documentation" href="../../index.html"/>
        <link rel="up" title="Module code" href="../index.html"/> 

  
  <script src="../../_static/js/modernizr.min.js"></script>

</head>

<body class="wy-body-for-nav" role="document">

  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search">
          

          
            <a href="../../index.html" class="icon icon-home"> Dynamic REST
          

          
          </a>

          
            
            
              <div class="version">
                1.3.15
              </div>
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
                <p class="caption"><span class="caption-text">Contents</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../tutorial.html">Dynamic REST Tutorial</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../dynamic_rest.html">dynamic_rest package</a></li>
</ul>

            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
        <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
        <a href="../../index.html">Dynamic REST</a>
      </nav>


      
      <div class="wy-nav-content">
        <div class="rst-content">
          





<div role="navigation" aria-label="breadcrumbs navigation">
  <ul class="wy-breadcrumbs">
    <li><a href="../../index.html">Docs</a> &raquo;</li>
      
          <li><a href="../index.html">Module code</a> &raquo;</li>
      
    <li>dynamic_rest.fields</li>
      <li class="wy-breadcrumbs-aside">
        
          
        
      </li>
  </ul>
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <h1>Source code for dynamic_rest.fields</h1><div class="highlight"><pre>
<span></span><span class="sd">&quot;&quot;&quot;This module contains custom field classes.&quot;&quot;&quot;</span>

<span class="kn">import</span> <span class="nn">importlib</span>
<span class="kn">import</span> <span class="nn">pickle</span>

<span class="kn">from</span> <span class="nn">django.utils</span> <span class="kn">import</span> <span class="n">six</span>
<span class="kn">from</span> <span class="nn">django.utils.functional</span> <span class="kn">import</span> <span class="n">cached_property</span>
<span class="kn">from</span> <span class="nn">rest_framework</span> <span class="kn">import</span> <span class="n">fields</span>
<span class="kn">from</span> <span class="nn">rest_framework.exceptions</span> <span class="kn">import</span> <span class="n">NotFound</span><span class="p">,</span> <span class="n">ParseError</span>
<span class="kn">from</span> <span class="nn">rest_framework.serializers</span> <span class="kn">import</span> <span class="n">SerializerMethodField</span>

<span class="kn">from</span> <span class="nn">dynamic_rest.bases</span> <span class="kn">import</span> <span class="n">DynamicSerializerBase</span>
<span class="kn">from</span> <span class="nn">dynamic_rest.conf</span> <span class="kn">import</span> <span class="n">settings</span>
<span class="kn">from</span> <span class="nn">dynamic_rest.meta</span> <span class="kn">import</span> <span class="n">is_field_remote</span>


<div class="viewcode-block" id="DynamicField"><a class="viewcode-back" href="../../dynamic_rest.html#dynamic_rest.fields.DynamicField">[docs]</a><span class="k">class</span> <span class="nc">DynamicField</span><span class="p">(</span><span class="n">fields</span><span class="o">.</span><span class="n">Field</span><span class="p">):</span></div>

    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Generic field base to capture additional custom field attributes.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span>
        <span class="bp">self</span><span class="p">,</span>
        <span class="n">requires</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
        <span class="n">deferred</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span>
        <span class="n">field_type</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
        <span class="o">**</span><span class="n">kwargs</span>
    <span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Arguments:</span>
<span class="sd">            deferred: Whether or not this field is deferred.</span>
<span class="sd">                Deferred fields are not included in the response,</span>
<span class="sd">                unless explicitly requested.</span>
<span class="sd">            field_type: Field data type, if not inferrable from model.</span>
<span class="sd">            requires: List of fields that this field depends on.</span>
<span class="sd">                Processed by the view layer during queryset build time.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">requires</span> <span class="o">=</span> <span class="n">requires</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">deferred</span> <span class="o">=</span> <span class="n">deferred</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">field_type</span> <span class="o">=</span> <span class="n">field_type</span>
        <span class="nb">super</span><span class="p">(</span><span class="n">DynamicField</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">to_representation</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">value</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">value</span>

    <span class="k">def</span> <span class="nf">to_internal_value</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">data</span>


<div class="viewcode-block" id="DynamicComputedField"><a class="viewcode-back" href="../../dynamic_rest.html#dynamic_rest.fields.DynamicComputedField">[docs]</a><span class="k">class</span> <span class="nc">DynamicComputedField</span><span class="p">(</span><span class="n">DynamicField</span><span class="p">):</span>
    <span class="k">pass</span></div>


<div class="viewcode-block" id="DynamicMethodField"><a class="viewcode-back" href="../../dynamic_rest.html#dynamic_rest.fields.DynamicMethodField">[docs]</a><span class="k">class</span> <span class="nc">DynamicMethodField</span><span class="p">(</span><span class="n">SerializerMethodField</span><span class="p">,</span> <span class="n">DynamicField</span><span class="p">):</span>
    <span class="k">pass</span></div>


<div class="viewcode-block" id="DynamicRelationField"><a class="viewcode-back" href="../../dynamic_rest.html#dynamic_rest.fields.DynamicRelationField">[docs]</a><span class="k">class</span> <span class="nc">DynamicRelationField</span><span class="p">(</span><span class="n">DynamicField</span><span class="p">):</span></div>

    <span class="sd">&quot;&quot;&quot;Field proxy for a nested serializer.</span>

<span class="sd">    Supports passing in the child serializer as a class or string,</span>
<span class="sd">    and resolves to the class after binding to the parent serializer.</span>

<span class="sd">    Will proxy certain arguments to the child serializer.</span>

<span class="sd">    Attributes:</span>
<span class="sd">        SERIALIZER_KWARGS: list of arguments that are passed</span>
<span class="sd">            to the child serializer.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="n">SERIALIZER_KWARGS</span> <span class="o">=</span> <span class="nb">set</span><span class="p">((</span><span class="s1">&#39;many&#39;</span><span class="p">,</span> <span class="s1">&#39;source&#39;</span><span class="p">))</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span>
            <span class="bp">self</span><span class="p">,</span>
            <span class="n">serializer_class</span><span class="p">,</span>
            <span class="n">many</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span>
            <span class="n">queryset</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span>
            <span class="n">embed</span><span class="o">=</span><span class="bp">False</span><span class="p">,</span>
            <span class="o">**</span><span class="n">kwargs</span>
    <span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Arguments:</span>
<span class="sd">            serializer_class: Serializer class (or string representation)</span>
<span class="sd">                to proxy.</span>
<span class="sd">            many: Boolean, if relation is to-many.</span>
<span class="sd">            queryset: Default queryset to apply when filtering for related</span>
<span class="sd">                objects.</span>
<span class="sd">            embed: If True, always embed related object(s). Will not sideload,</span>
<span class="sd">                and will include the full object unless specifically excluded.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">kwargs</span> <span class="o">=</span> <span class="n">kwargs</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_serializer_class</span> <span class="o">=</span> <span class="n">serializer_class</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">bound</span> <span class="o">=</span> <span class="bp">False</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">queryset</span> <span class="o">=</span> <span class="n">queryset</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">embed</span> <span class="o">=</span> <span class="n">embed</span>
        <span class="k">if</span> <span class="s1">&#39;.&#39;</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;source&#39;</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">):</span>
            <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s1">&#39;Nested relationships are not supported&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="s1">&#39;link&#39;</span> <span class="ow">in</span> <span class="n">kwargs</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">link</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s1">&#39;link&#39;</span><span class="p">)</span>
        <span class="nb">super</span><span class="p">(</span><span class="n">DynamicRelationField</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">kwargs</span><span class="p">[</span><span class="s1">&#39;many&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">many</span>

    <span class="k">def</span> <span class="nf">get_model</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Get the child serializer&#39;s model.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="nb">getattr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">serializer_class</span><span class="o">.</span><span class="n">Meta</span><span class="p">,</span> <span class="s1">&#39;model&#39;</span><span class="p">,</span> <span class="bp">None</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">bind</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Bind to the parent serializer.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">bound</span><span class="p">:</span>  <span class="c1"># Prevent double-binding</span>
            <span class="k">return</span>
        <span class="nb">super</span><span class="p">(</span><span class="n">DynamicRelationField</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">bind</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">bound</span> <span class="o">=</span> <span class="bp">True</span>
        <span class="n">parent_model</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">parent</span><span class="o">.</span><span class="n">Meta</span><span class="p">,</span> <span class="s1">&#39;model&#39;</span><span class="p">,</span> <span class="bp">None</span><span class="p">)</span>

        <span class="n">remote</span> <span class="o">=</span> <span class="n">is_field_remote</span><span class="p">(</span><span class="n">parent_model</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">source</span><span class="p">)</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">model_field</span> <span class="o">=</span> <span class="n">parent_model</span><span class="o">.</span><span class="n">_meta</span><span class="o">.</span><span class="n">get_field_by_name</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">source</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
        <span class="k">except</span><span class="p">:</span>
            <span class="c1"># model field may not be available for m2o fields with no</span>
            <span class="c1"># related_name</span>
            <span class="n">model_field</span> <span class="o">=</span> <span class="bp">None</span>

        <span class="k">if</span> <span class="s1">&#39;required&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">kwargs</span> <span class="ow">and</span> <span class="p">(</span>
                <span class="n">remote</span> <span class="ow">or</span> <span class="p">(</span>
                    <span class="n">model_field</span> <span class="ow">and</span> <span class="p">(</span>
                        <span class="n">model_field</span><span class="o">.</span><span class="n">has_default</span><span class="p">()</span> <span class="ow">or</span> <span class="n">model_field</span><span class="o">.</span><span class="n">null</span>
                    <span class="p">)</span>
                <span class="p">)</span>
        <span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">required</span> <span class="o">=</span> <span class="bp">False</span>
        <span class="k">if</span> <span class="s1">&#39;allow_null&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">kwargs</span> <span class="ow">and</span> <span class="nb">getattr</span><span class="p">(</span>
                <span class="n">model_field</span><span class="p">,</span> <span class="s1">&#39;null&#39;</span><span class="p">,</span> <span class="bp">False</span>
        <span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">allow_null</span> <span class="o">=</span> <span class="bp">True</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">model_field</span> <span class="o">=</span> <span class="n">model_field</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">root_serializer</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Return the root serializer (serializer for the primary resource).&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="s1">&#39;_root_serializer&#39;</span><span class="p">):</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_root_serializer</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">parent</span><span class="p">:</span>
            <span class="c1"># Don&#39;t cache, so that we&#39;d recompute if parent is set.</span>
            <span class="k">return</span> <span class="bp">None</span>

        <span class="n">node</span> <span class="o">=</span> <span class="bp">self</span>
        <span class="n">seen</span> <span class="o">=</span> <span class="nb">set</span><span class="p">()</span>
        <span class="k">while</span> <span class="bp">True</span><span class="p">:</span>
            <span class="n">seen</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">node</span><span class="p">)</span>
            <span class="k">if</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">node</span><span class="p">,</span> <span class="s1">&#39;parent&#39;</span><span class="p">,</span> <span class="bp">None</span><span class="p">):</span>
                <span class="n">node</span> <span class="o">=</span> <span class="n">node</span><span class="o">.</span><span class="n">parent</span>
                <span class="k">if</span> <span class="n">node</span> <span class="ow">in</span> <span class="n">seen</span><span class="p">:</span>
                    <span class="k">return</span> <span class="bp">None</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">_root_serializer</span> <span class="o">=</span> <span class="n">node</span>
                <span class="k">break</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_root_serializer</span>

    <span class="k">def</span> <span class="nf">_get_cached_serializer</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">init_args</span><span class="p">):</span>
        <span class="n">enabled</span> <span class="o">=</span> <span class="n">settings</span><span class="o">.</span><span class="n">ENABLE_SERIALIZER_CACHE</span>

        <span class="n">root</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">root_serializer</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">root</span> <span class="ow">or</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">field_name</span> <span class="ow">or</span> <span class="ow">not</span> <span class="n">enabled</span><span class="p">:</span>
            <span class="c1"># Not enough info to use cache.</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">serializer_class</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">init_args</span><span class="p">)</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">root</span><span class="p">,</span> <span class="s1">&#39;_descendant_serializer_cache&#39;</span><span class="p">):</span>
            <span class="c1"># Initialize dict to use as cache on root serializer.</span>
            <span class="c1"># Arguably this is a Serializer concern, but we&#39;ll do it</span>
            <span class="c1"># here so it&#39;s agnostic to the exact type of the root</span>
            <span class="c1"># serializer (i.e. it could be a DRF serializer).</span>
            <span class="n">root</span><span class="o">.</span><span class="n">_descendant_serializer_cache</span> <span class="o">=</span> <span class="p">{}</span>

        <span class="n">key_dict</span> <span class="o">=</span> <span class="p">{</span>
            <span class="s1">&#39;parent&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">parent</span><span class="o">.</span><span class="n">__class__</span><span class="o">.</span><span class="n">__name__</span><span class="p">,</span>
            <span class="s1">&#39;field&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">field_name</span><span class="p">,</span>
            <span class="s1">&#39;args&#39;</span><span class="p">:</span> <span class="n">args</span><span class="p">,</span>
            <span class="s1">&#39;init_args&#39;</span><span class="p">:</span> <span class="n">init_args</span>
        <span class="p">}</span>
        <span class="n">cache_key</span> <span class="o">=</span> <span class="nb">hash</span><span class="p">(</span><span class="n">pickle</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="n">key_dict</span><span class="p">))</span>

        <span class="k">if</span> <span class="n">cache_key</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">root</span><span class="o">.</span><span class="n">_descendant_serializer_cache</span><span class="p">:</span>
            <span class="n">szr</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">serializer_class</span><span class="p">(</span>
                <span class="o">*</span><span class="n">args</span><span class="p">,</span>
                <span class="o">**</span><span class="n">init_args</span>
            <span class="p">)</span>
            <span class="n">root</span><span class="o">.</span><span class="n">_descendant_serializer_cache</span><span class="p">[</span><span class="n">cache_key</span><span class="p">]</span> <span class="o">=</span> <span class="n">szr</span>

        <span class="k">return</span> <span class="n">root</span><span class="o">.</span><span class="n">_descendant_serializer_cache</span><span class="p">[</span><span class="n">cache_key</span><span class="p">]</span>

    <span class="k">def</span> <span class="nf">_get_request_fields_from_parent</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Get request fields from the parent serializer.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">parent</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">None</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="nb">getattr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">parent</span><span class="p">,</span> <span class="s1">&#39;request_fields&#39;</span><span class="p">):</span>
            <span class="k">return</span> <span class="bp">None</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">parent</span><span class="o">.</span><span class="n">request_fields</span><span class="p">,</span> <span class="nb">dict</span><span class="p">):</span>
            <span class="k">return</span> <span class="bp">None</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">parent</span><span class="o">.</span><span class="n">request_fields</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">field_name</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">_inherit_parent_kwargs</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Extract any necessary attributes from parent serializer to</span>
<span class="sd">        propagate down to child serializer.</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">parent</span> <span class="ow">or</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">_is_dynamic</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">kwargs</span>

        <span class="k">if</span> <span class="s1">&#39;request_fields&#39;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">kwargs</span><span class="p">:</span>
            <span class="c1"># If &#39;request_fields&#39; isn&#39;t explicitly set, pull it from the</span>
            <span class="c1"># parent serializer.</span>
            <span class="n">request_fields</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_request_fields_from_parent</span><span class="p">()</span>
            <span class="k">if</span> <span class="n">request_fields</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
                <span class="c1"># Default to &#39;id_only&#39; for nested serializers.</span>
                <span class="n">request_fields</span> <span class="o">=</span> <span class="bp">True</span>
            <span class="n">kwargs</span><span class="p">[</span><span class="s1">&#39;request_fields&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">request_fields</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">embed</span> <span class="ow">and</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;request_fields&#39;</span><span class="p">)</span> <span class="ow">is</span> <span class="bp">True</span><span class="p">:</span>
            <span class="c1"># If &#39;embed&#39; then make sure we fetch the full object.</span>
            <span class="n">kwargs</span><span class="p">[</span><span class="s1">&#39;request_fields&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">{}</span>

        <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">parent</span><span class="p">,</span> <span class="s1">&#39;sideload&#39;</span><span class="p">):</span>
            <span class="n">kwargs</span><span class="p">[</span><span class="s1">&#39;sideload&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">parent</span><span class="o">.</span><span class="n">sideload</span>

        <span class="k">return</span> <span class="n">kwargs</span>

    <span class="k">def</span> <span class="nf">get_serializer</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Get an instance of the child serializer.&quot;&quot;&quot;</span>
        <span class="n">init_args</span> <span class="o">=</span> <span class="p">{</span>
            <span class="n">k</span><span class="p">:</span> <span class="n">v</span> <span class="k">for</span> <span class="n">k</span><span class="p">,</span> <span class="n">v</span> <span class="ow">in</span> <span class="n">six</span><span class="o">.</span><span class="n">iteritems</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">kwargs</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">k</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">SERIALIZER_KWARGS</span>
        <span class="p">}</span>

        <span class="n">kwargs</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_inherit_parent_kwargs</span><span class="p">(</span><span class="n">kwargs</span><span class="p">)</span>
        <span class="n">init_args</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">kwargs</span><span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">embed</span> <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">_is_dynamic</span><span class="p">:</span>
            <span class="n">init_args</span><span class="p">[</span><span class="s1">&#39;embed&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="bp">True</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_get_cached_serializer</span><span class="p">(</span><span class="n">args</span><span class="p">,</span> <span class="n">init_args</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">serializer</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="s1">&#39;_serializer&#39;</span><span class="p">):</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_serializer</span>

        <span class="n">serializer</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_serializer</span><span class="p">()</span>
        <span class="n">serializer</span><span class="o">.</span><span class="n">parent</span> <span class="o">=</span> <span class="bp">self</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">_serializer</span> <span class="o">=</span> <span class="n">serializer</span>
        <span class="k">return</span> <span class="n">serializer</span>

    <span class="nd">@cached_property</span>
    <span class="k">def</span> <span class="nf">_is_dynamic</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Return True if the child serializer is dynamic.&quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="nb">issubclass</span><span class="p">(</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">serializer_class</span><span class="p">,</span>
            <span class="n">DynamicSerializerBase</span>
        <span class="p">)</span>

    <span class="k">def</span> <span class="nf">get_attribute</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">instance</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">instance</span>

    <span class="k">def</span> <span class="nf">to_representation</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">instance</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Represent the relationship, either as an ID or object.&quot;&quot;&quot;</span>
        <span class="n">serializer</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">serializer</span>
        <span class="n">model</span> <span class="o">=</span> <span class="n">serializer</span><span class="o">.</span><span class="n">get_model</span><span class="p">()</span>
        <span class="n">source</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">source</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">kwargs</span><span class="p">[</span><span class="s1">&#39;many&#39;</span><span class="p">]</span> <span class="ow">and</span> <span class="n">serializer</span><span class="o">.</span><span class="n">id_only</span><span class="p">():</span>
            <span class="c1"># attempt to optimize by reading the related ID directly</span>
            <span class="c1"># from the current instance rather than from the related object</span>
            <span class="n">source_id</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">%s</span><span class="s1">_id&#39;</span> <span class="o">%</span> <span class="n">source</span>
            <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">instance</span><span class="p">,</span> <span class="n">source_id</span><span class="p">):</span>
                <span class="k">return</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">instance</span><span class="p">,</span> <span class="n">source_id</span><span class="p">)</span>

        <span class="k">if</span> <span class="n">model</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
            <span class="n">related</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">instance</span><span class="p">,</span> <span class="n">source</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="n">related</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">instance</span><span class="p">,</span> <span class="n">source</span><span class="p">)</span>
            <span class="k">except</span> <span class="n">model</span><span class="o">.</span><span class="n">DoesNotExist</span><span class="p">:</span>
                <span class="k">return</span> <span class="bp">None</span>

        <span class="k">if</span> <span class="n">related</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">None</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">serializer</span><span class="o">.</span><span class="n">to_representation</span><span class="p">(</span><span class="n">related</span><span class="p">)</span>
        <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
            <span class="c1"># Provide more context to help debug these cases</span>
            <span class="k">if</span> <span class="n">settings</span><span class="o">.</span><span class="n">DEBUG</span><span class="p">:</span>
                <span class="kn">import</span> <span class="nn">traceback</span>
                <span class="n">traceback</span><span class="o">.</span><span class="n">print_exc</span><span class="p">()</span>
            <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span>
                <span class="s2">&quot;Failed to serialize </span><span class="si">%s</span><span class="s2">.</span><span class="si">%s</span><span class="s2">: </span><span class="si">%s</span><span class="se">\n</span><span class="s2">Obj: </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span>
                <span class="p">(</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">parent</span><span class="o">.</span><span class="n">__class__</span><span class="o">.</span><span class="n">__name__</span><span class="p">,</span>
                    <span class="bp">self</span><span class="o">.</span><span class="n">source</span><span class="p">,</span>
                    <span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">),</span>
                    <span class="nb">repr</span><span class="p">(</span><span class="n">related</span><span class="p">)</span>
                <span class="p">)</span>
            <span class="p">)</span>

    <span class="k">def</span> <span class="nf">to_internal_value_single</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span> <span class="n">serializer</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Return the underlying object, given the serialized form.&quot;&quot;&quot;</span>
        <span class="n">related_model</span> <span class="o">=</span> <span class="n">serializer</span><span class="o">.</span><span class="n">Meta</span><span class="o">.</span><span class="n">model</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="n">related_model</span><span class="p">):</span>
            <span class="k">return</span> <span class="n">data</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">instance</span> <span class="o">=</span> <span class="n">related_model</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">pk</span><span class="o">=</span><span class="n">data</span><span class="p">)</span>
        <span class="k">except</span> <span class="n">related_model</span><span class="o">.</span><span class="n">DoesNotExist</span><span class="p">:</span>
            <span class="k">raise</span> <span class="n">NotFound</span><span class="p">(</span>
                <span class="s2">&quot;&#39;</span><span class="si">%s</span><span class="s2"> object with ID=</span><span class="si">%s</span><span class="s2"> not found&quot;</span> <span class="o">%</span>
                <span class="p">(</span><span class="n">related_model</span><span class="o">.</span><span class="n">__name__</span><span class="p">,</span> <span class="n">data</span><span class="p">)</span>
            <span class="p">)</span>
        <span class="k">return</span> <span class="n">instance</span>

    <span class="k">def</span> <span class="nf">to_internal_value</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">data</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Return the underlying object(s), given the serialized form.&quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">kwargs</span><span class="p">[</span><span class="s1">&#39;many&#39;</span><span class="p">]:</span>
            <span class="n">serializer</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">serializer</span><span class="o">.</span><span class="n">child</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="nb">list</span><span class="p">):</span>
                <span class="k">raise</span> <span class="n">ParseError</span><span class="p">(</span><span class="s2">&quot;&#39;</span><span class="si">%s</span><span class="s2">&#39; value must be a list&quot;</span> <span class="o">%</span> <span class="bp">self</span><span class="o">.</span><span class="n">field_name</span><span class="p">)</span>
            <span class="k">return</span> <span class="p">[</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">to_internal_value_single</span><span class="p">(</span>
                    <span class="n">instance</span><span class="p">,</span>
                    <span class="n">serializer</span>
                <span class="p">)</span> <span class="k">for</span> <span class="n">instance</span> <span class="ow">in</span> <span class="n">data</span>
            <span class="p">]</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">to_internal_value_single</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">serializer</span><span class="p">)</span>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">serializer_class</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;Get the class of the child serializer.</span>

<span class="sd">        Resolves string imports.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">serializer_class</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_serializer_class</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">serializer_class</span><span class="p">,</span> <span class="n">six</span><span class="o">.</span><span class="n">string_types</span><span class="p">):</span>
            <span class="k">return</span> <span class="n">serializer_class</span>

        <span class="n">parts</span> <span class="o">=</span> <span class="n">serializer_class</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;.&#39;</span><span class="p">)</span>
        <span class="n">module_path</span> <span class="o">=</span> <span class="s1">&#39;.&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">parts</span><span class="p">[:</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">module_path</span><span class="p">:</span>
            <span class="k">if</span> <span class="nb">getattr</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="s1">&#39;parent&#39;</span><span class="p">,</span> <span class="bp">None</span><span class="p">)</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span>
                    <span class="s2">&quot;Can not load serializer &#39;</span><span class="si">%s</span><span class="s2">&#39;&quot;</span> <span class="o">%</span> <span class="n">serializer_class</span> <span class="o">+</span>
                    <span class="s1">&#39; before binding or without specifying full path&#39;</span><span class="p">)</span>

            <span class="c1"># try the module of the parent class</span>
            <span class="n">module_path</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">parent</span><span class="o">.</span><span class="n">__module__</span>

        <span class="n">module</span> <span class="o">=</span> <span class="n">importlib</span><span class="o">.</span><span class="n">import_module</span><span class="p">(</span><span class="n">module_path</span><span class="p">)</span>
        <span class="n">serializer_class</span> <span class="o">=</span> <span class="nb">getattr</span><span class="p">(</span><span class="n">module</span><span class="p">,</span> <span class="n">parts</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">])</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">_serializer_class</span> <span class="o">=</span> <span class="n">serializer_class</span>
        <span class="k">return</span> <span class="n">serializer_class</span>


<div class="viewcode-block" id="CountField"><a class="viewcode-back" href="../../dynamic_rest.html#dynamic_rest.fields.CountField">[docs]</a><span class="k">class</span> <span class="nc">CountField</span><span class="p">(</span><span class="n">DynamicComputedField</span><span class="p">):</span></div>

    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Computed field that counts the number of elements in another field.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">serializer_source</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Arguments:</span>
<span class="sd">            serializer_source: A serializer field.</span>
<span class="sd">            unique: Whether or not to perform a count of distinct elements.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">field_type</span> <span class="o">=</span> <span class="nb">int</span>
        <span class="c1"># Use `serializer_source`, which indicates a field at the API level,</span>
        <span class="c1"># instead of `source`, which indicates a field at the model level.</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">serializer_source</span> <span class="o">=</span> <span class="n">serializer_source</span>
        <span class="c1"># Set `source` to an empty value rather than the field name to avoid</span>
        <span class="c1"># an attempt to look up this field.</span>
        <span class="n">kwargs</span><span class="p">[</span><span class="s1">&#39;source&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="s1">&#39;&#39;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">unique</span> <span class="o">=</span> <span class="n">kwargs</span><span class="o">.</span><span class="n">pop</span><span class="p">(</span><span class="s1">&#39;unique&#39;</span><span class="p">,</span> <span class="bp">True</span><span class="p">)</span>
        <span class="k">return</span> <span class="nb">super</span><span class="p">(</span><span class="n">CountField</span><span class="p">,</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">__init__</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">get_attribute</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">obj</span><span class="p">):</span>
        <span class="n">source</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">serializer_source</span>
        <span class="k">if</span> <span class="n">source</span> <span class="ow">not</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">parent</span><span class="o">.</span><span class="n">fields</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">None</span>
        <span class="n">value</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">parent</span><span class="o">.</span><span class="n">fields</span><span class="p">[</span><span class="n">source</span><span class="p">]</span><span class="o">.</span><span class="n">get_attribute</span><span class="p">(</span><span class="n">obj</span><span class="p">)</span>
        <span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">parent</span><span class="o">.</span><span class="n">fields</span><span class="p">[</span><span class="n">source</span><span class="p">]</span><span class="o">.</span><span class="n">to_representation</span><span class="p">(</span><span class="n">value</span><span class="p">)</span>

        <span class="c1"># How to count None is undefined... let the consumer decide.</span>
        <span class="k">if</span> <span class="n">data</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">None</span>

        <span class="c1"># Check data type. Technically len() works on dicts, strings, but</span>
        <span class="c1"># since this is a &quot;count&quot; field, we&#39;ll limit to list, set, tuple.</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">data</span><span class="p">,</span> <span class="p">(</span><span class="nb">list</span><span class="p">,</span> <span class="nb">set</span><span class="p">,</span> <span class="nb">tuple</span><span class="p">)):</span>
            <span class="k">raise</span> <span class="ne">TypeError</span><span class="p">(</span>
                <span class="s2">&quot;&#39;</span><span class="si">%s</span><span class="s2">&#39; is </span><span class="si">%s</span><span class="s2">. Must be list, set or tuple to be countable.&quot;</span> <span class="o">%</span> <span class="p">(</span>
                    <span class="n">source</span><span class="p">,</span> <span class="nb">type</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
                <span class="p">)</span>
            <span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">unique</span><span class="p">:</span>
            <span class="c1"># Try to create unique set. This may fail if `data` contains</span>
            <span class="c1"># non-hashable elements (like dicts).</span>
            <span class="k">try</span><span class="p">:</span>
                <span class="n">data</span> <span class="o">=</span> <span class="nb">set</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
            <span class="k">except</span> <span class="ne">TypeError</span><span class="p">:</span>
                <span class="k">pass</span>

        <span class="k">return</span> <span class="nb">len</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
</pre></div>

           </div>
          </div>
          <footer>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2016, ant@altschool.com, ryo@altschool.com.

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  

    <script type="text/javascript">
        var DOCUMENTATION_OPTIONS = {
            URL_ROOT:'../../',
            VERSION:'1.3.15',
            COLLAPSE_INDEX:false,
            FILE_SUFFIX:'.html',
            HAS_SOURCE:  true
        };
    </script>
      <script type="text/javascript" src="../../_static/jquery.js"></script>
      <script type="text/javascript" src="../../_static/underscore.js"></script>
      <script type="text/javascript" src="../../_static/doctools.js"></script>

  

  
  
    <script type="text/javascript" src="../../_static/js/theme.js"></script>
  

  
  
  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.StickyNav.enable();
      });
  </script>
   

</body>
</html>